package com.itheima.server.controller;

import com.itheima.model.dto.RecommendUserDto;
import com.itheima.model.vo.NearUserVo;
import com.itheima.model.vo.PageResult;
import com.itheima.model.vo.TodayBest;
import com.itheima.server.interceptor.UserHolder;
import com.itheima.server.service.TanhuaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {
    @Autowired
    private TanhuaService tanhuaService;
    /*今日佳人*/
    @GetMapping("/todayBest")
    public ResponseEntity todayBest(){
       return ResponseEntity.ok(tanhuaService.todayBest(UserHolder.getUserId()));

    }
    /*推荐朋友*/
    @GetMapping("/recommendation")
    public ResponseEntity<PageResult> recommendation(RecommendUserDto dto){
        PageResult pageResult=tanhuaService.recommendation(dto);
        return ResponseEntity.ok(pageResult);
    }
    /*佳人信息*/
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long userId){
       TodayBest best= tanhuaService.personalInfo(userId);
       return ResponseEntity.ok(best);
    }
    /*查询陌生人问题*/
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestion(Long userId){
        String text= tanhuaService.strangerQuestion(userId);
        return ResponseEntity.ok(text);
    }
    //回复陌生人问题
    @PostMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(@RequestBody Map<String,String> map){
        Long userId = Long.valueOf(map.get("userId"));
        String reply = map.get("reply");
        tanhuaService.replyQuestions(userId,reply);
        return ResponseEntity.ok(null);
    }

    /*探花-左滑右滑*/
    @GetMapping("/cards")
    public ResponseEntity cards(){
       List<TodayBest> list= tanhuaService.queryCardsList();
       return ResponseEntity.ok(list);
    }
    /*探花-喜欢*/
    @GetMapping("/{id}/love")
    public ResponseEntity love(@PathVariable("id") Long likeUserId){
        tanhuaService.love(likeUserId);
        return ResponseEntity.ok(null);
    }
    /*探花-不喜欢*/
    @GetMapping("/{id}/unlove")
    public ResponseEntity unlove(@PathVariable("id") Long likeUserId){
        tanhuaService.notlove(likeUserId);
        return ResponseEntity.ok(null);
    }
    /*搜附近*/
    @GetMapping("/search")
    public ResponseEntity search(String gender,@RequestParam(defaultValue = "20000")String distance){
        List<NearUserVo> nearUserVos =tanhuaService.search(gender,distance);
        return ResponseEntity.ok(nearUserVos);
    }
}
